package com.weike.wk_android.view.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.trello.rxlifecycle3.components.support.RxFragment;
import com.weike.wk_android.R;
import com.weike.wk_android.utils.Utils;
import com.weike.wk_android.view.activity.CarpoolActivity;
import com.weike.wk_android.view.activity.DatingActivity;
import com.weike.wk_android.view.activity.DiscountActivity;
import com.weike.wk_android.view.activity.RecruitmentActivity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 发现页面
 */
public class FoundFragment extends RxFragment {
    @BindView(R.id.title_left)
    TextView location;
    @BindView(R.id.title)
    TextView title;
    private View root;
    // 添加绑定解除
    private Unbinder unbinder;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (root == null) {
            root = inflater.inflate(R.layout.fragment_found, container, false);
        }

        // 加入ButterKnife绑定
        unbinder = ButterKnife.bind(this, root);

        initView();

        return root;
    }

    /**
     * 初始化视图
     */
    private void initView() {
        // 设置左控件不可见
        location.setVisibility(View.GONE);
        // 设置标题名
        title.setText(Utils.getString(R.string.found));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();

        // 解除绑定
        if (unbinder != null) {
            unbinder.unbind();
        }
    }

    @OnClick({
            R.id.found_recruitment_layer,
            R.id.found_dating_layer,
            R.id.found_carpool_layer,
            R.id.found_discount_layer
    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.found_recruitment_layer:
                gotoRecruitment();
                break;
            case R.id.found_dating_layer:
                gotoDating();
                break;
            case R.id.found_carpool_layer:
                gotoCarpool();
                break;
            case R.id.found_discount_layer:
                gotoDisCount();
                break;
        }
    }

    /**
     * 跳转折扣信息页面
     */
    private void gotoDisCount() {
        startActivity(new Intent(getActivity(), DiscountActivity.class));
    }

    /**
     * 跳转拼车页面
     */
    private void gotoCarpool() {
        startActivity(new Intent(getActivity(), CarpoolActivity.class));
    }

    /**
     * 跳转相亲交友页面
     */
    private void gotoDating() {
        startActivity(new Intent(getActivity(), DatingActivity.class));
    }

    /**
     * 跳转招聘页面
     */
    @SuppressLint("ResourceType")
    private void gotoRecruitment() {
        startActivity(new Intent(getActivity(), RecruitmentActivity.class));
    }
}
